package com.finger.hospservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.finger.commonutil.exception.YyghException;
import com.finger.hospservice.mapper.HospSetMapper;
import com.finger.hospservice.service.HospSetService;
import com.finger.modelservice.model.hosp.HospitalSet;
import com.finger.modelservice.result.ResultCodeEnum;
import com.finger.modelservice.vo.order.SignInfoVo;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
public class HospSetServiceImpl extends ServiceImpl<HospSetMapper, HospitalSet> implements HospSetService {
    @Override
    public String getHospSignByHoscode(String hoscode) {

        QueryWrapper<HospitalSet> hospitalSetQueryWrapper = new QueryWrapper<>();

        hospitalSetQueryWrapper.eq("hoscode",hoscode);

        HospitalSet hospitalSet = baseMapper.selectOne(hospitalSetQueryWrapper);

        if(hospitalSet.getStatus()==0){
            throw new YyghException("该医院设置已被锁定",212);
        }
        return hospitalSet.getSignKey();
    }

    @Override
    public SignInfoVo findSignInfoVO(String hoscode) {

        HospitalSet hospitalSet = baseMapper.selectOne(new QueryWrapper<HospitalSet>().eq("hoscode", hoscode).eq("status",1));

        if(hospitalSet == null){
            throw new YyghException(ResultCodeEnum.HOSPITAL_OPEN);
        }
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());

        return signInfoVo;
    }
}
